﻿<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
        <meta charset="utf-8">
		<meta name="keywords" content="" />
		<meta name="description" content="" />
		<meta content="width=device-width, minimum-scale=1,initial-scale=1, maximum-scale=1, user-scalable=1" id="viewport" name="viewport" />
		<meta content="yes" name="apple-mobile-web-app-capable" />
		<meta content="black" name="apple-mobile-web-app-status-bar-style" />
		<meta content="telephone=no" name="format-detection" />
  		<link rel="stylesheet" href="../../resource/weuimin.css"/>
		<link rel="stylesheet" href="../../resource/example.css"/>
    	<link type="text/css" rel="stylesheet" href="../../template/css/weui.css" />
    	<link type="text/css" rel="stylesheet" href="../../template/css/weui2.css" />
    	<link type="text/css" rel="stylesheet" href="../../template/css/weui3.css" />
        <link rel="stylesheet" href="../../resource/weuimin.css" />
		<link type="text/css" rel="stylesheet" href="../../template/css/com/com.css"/>
		<link type="text/css" rel="stylesheet" href="../../template/css/list/style.css"/>
        <script type="text/javascript" src="../../script/constants.js"></script>
		<script src="../../template/js/jquery.js"></script>
		<script src="../../template/js/com/com.js"></script>
		<script src="../../template/js/com/template.js"></script>
		<script src="../../resource/my.js"></script>
		<script src="../../script/api.js"></script>
		<script src="../../../../template/js/jquery.js"></script>
    	<link type="text/css" rel="stylesheet" href="../../template/css/good/index.css" />
   		<script src="../../template/js/zeptomin.js"></script>
              <link rel="stylesheet" href="../../resource/jinsuistyle.css" />
   <script type="text/javascript">
   		var spmc = '';
   		var price = '';
   		var dm = '';
          apiready=function(){
           if(api.systemType == "ios"){
			   document.getElementById("statusBar").style.background = "#298cb4";
			}
           $api.fixStatusBar( $api.dom('header') );
           $("#loadingToast").show();
            var header = $api.byId('jsheader');
            if(api.systemType=='ios'){
        			$api.fixIos7Bar(header);
        		}
//      		else{
//      			$api.fixStatusBar(header);
//      		}
        	    dm = api.pageParam.spdm;
        		api.ajax({
     	           url:url.zcmx+"?spdm="+dm,
     	           method: 'get',
		            cache: 'false',
		            timeout: 30,
		            dataTpye: 'json',
		          }, function(dd,err){
		          $("#loadingToast").hide();
	        	     var data = eval("("+ dd.json +")");
     	        	   if(data[0].kc <=0){
     	        		  $("#title").html(data[0].mc + "<b> (无货)</b>");
     	        		  $("#xgButton").hide();
     	        	   }else{
     	        	   		$("#title").html(data[0].mc);
     	        	   }
     	        	   $api.attr($api.byId("img"), "src", data[0].pic);
     	        	   //$("#img").attr("src",data[0].pic);
     	        	   $("#price").html("￥" + data[0].price);
     	        	   var sps = data[0].spms.split('&#x000A;');
     	        	   var html = "";
     	        	   for(var i=0;i<sps.length;i++){
     	        		   html += "<li>"+ sps[i] + "</li>";
     	        	   }
     	        	   $("#spms").html(html);
     	        	  spmc = data[0].mc;
     	        	  price = data[0].price;
     	           });
//      		<%if(sl != null && spmc != null && price!=null){%>
//      			location.href='#xgButton';
//      			 $.toast("您已经选购了‘<%=spmc%>’！");
//      		<%}%>
        	}

        	function subtj(){
        	    var sl = $("#sl").val();
        		console.info(spmc+","+price+","+sl+","+dm);
        		var product =
			        {
		              'dm':dm,       //属性名用引号括起来，属性间由逗号隔开
		              'spmc': spmc,
		              'sl':sl,
		              'price':price
			        };
			     	cart.addproduct(product);
				    api.toast({
				        msg:spmc+"已添加到购物筐"
			        });
        	}

        	function closeWin(){
             api.closeWin();
            }


            utils = {
		    setParam : function (name,value){
		        localStorage.setItem(name,value)
		    },
		    getParam : function(name){
		        return localStorage.getItem(name)
		    }
		}



		product={
		    dm:0,
		    spmc:"",
		    sl:0,
		    price:0.00,
		};

		orderdetail={
		  //  username:"",
		  //  phone:"",
		  //  address:"",
		  //  zipcode:"",
		    totalNumber:0,
		    totalAmount:0.00
		}

		cart = {
		    //向购物车中添加商品
		    addproduct:function(product){
		        var JSCGShoppingCart = utils.getParam("JSCGShoppingCart");
		        if(JSCGShoppingCart==null||JSCGShoppingCart==""){
		                        //第一次加入商品
		            var jsonstr = {"productlist":[{"dm":product.dm,"spmc":product.spmc,"sl":product.sl,"price":product.price}],"totalNumber":product.sl,"totalAmount":(product.price*product.sl)};
		            utils.setParam("JSCGShoppingCart",JSON.stringify(jsonstr));
		        }else{
		            var jsonstr = JSON.parse(JSCGShoppingCart);
		            var productlist = jsonstr.productlist;
		            var result=false;
		            //查找购物车中是否有该商品
		            for(var i in productlist){
		                if(productlist[i].dm==product.dm){
		                    productlist[i].sl=parseInt(productlist[i].sl)+parseInt(product.sl);
		                    result = true;
		                }
		            }
		            if(!result){
		                //没有该商品就直接加进去
		                productlist.push({"dm":product.dm,"spmc":product.spmc,"sl":product.sl,"price":product.price});
		            }
		                        //重新计算总价
		            jsonstr.totalNumber=parseInt(jsonstr.totalNumber)+parseInt(product.sl);
		//          jsonstr.totalAmount=parseFloat(jsonstr.totalAmount)+(parseInt(product.num)*parseFloat(product.price));
		            jsonstr.totalAmount=accAdd(jsonstr.totalAmount, accMul(product.sl, product.price));
		            orderdetail.totalNumber = jsonstr.totalNumber;
		            orderdetail.totalAmount = jsonstr.totalAmount;
		            //保存购物车
		            utils.setParam("JSCGShoppingCart",JSON.stringify(jsonstr));
		        }
		     }
		  };


		  			// 两个浮点数求和
			function accAdd(num1, num2) {
			        var r1, r2, m;
			        try {
			                r1 = num1.toString().split('.')[1].length;
			        } catch(e) {
			                r1 = 0;
			        }
			        try {
			                r2 = num2.toString().split(".")[1].length;
			        } catch(e) {
			                r2 = 0;
			        }
			        m = Math.pow(10, Math.max(r1, r2));
			        // return (num1*m+num2*m)/m;
			        return Math.round(num1 * m + num2 * m) / m;
			}

			// 两个浮点数相减
			function accSub(num1, num2) {
			        var r1, r2, m;
			        try {
			                r1 = num1.toString().split('.')[1].length;
			        } catch(e) {
			                r1 = 0;
			        }
			        try {
			                r2 = num2.toString().split(".")[1].length;
			        } catch(e) {
			                r2 = 0;
			        }
			        m = Math.pow(10, Math.max(r1, r2));
			        n = (r1 >= r2) ? r1 : r2;
			        return (Math.round(num1 * m - num2 * m) / m).toFixed(n);
			}

			// 两数相除
			function accDiv(num1, num2) {
			        var t1, t2, r1, r2;
			        try {
			                t1 = num1.toString().split('.')[1].length;
			        } catch(e) {
			                t1 = 0;
			        }
			        try {
			                t2 = num2.toString().split(".")[1].length;
			        } catch(e) {
			                t2 = 0;
			        }
			        r1 = Number(num1.toString().replace(".", ""));
			        r2 = Number(num2.toString().replace(".", ""));
			        return (r1 / r2) * Math.pow(10, t2 - t1);
			}

			// 浮点数相乘
			function accMul(num1, num2) {
			        var m = 0, s1 = num1.toString(), s2 = num2.toString();
			        try {
			                m += s1.split(".")[1].length
			        } catch(e) {
			        };
			        try {
			                m += s2.split(".")[1].length
			        } catch(e) {
			        };
			        return Number(s1.replace(".", "")) * Number(s2.replace(".", "")) / Math.pow(10, m);
			}

      function goMain(){
        api.closeWin();
      }

        </script>
        <style>
        	.pxui-light-button{width:49%;}
        	#title{color:#fb4e3a;}
        	.pxui-light-button,input.pxui-light-button{background:#005da9;border-color:#005dcc;color:#fff;}
        </style>
  </head>

  <body>
    <header id="statusBar">
    <div id="jsheader">
        <nav id="jsnav">
            <a id="jsleft" tapmode="" onclick="api.closeToWin({name: 'root'});">
                <span>主页</span>
            </a>
            <div id="jsmiddle">
                <strong id="jstitle">金穗采购</strong>
            </div>
            <a id="jsright">
              <span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
            </a>
        </nav>
    </div>
    </header>
    <div class="com-content">
		<!-- <div class="com-header-area" id="js-com-header-area">
			<a href="" class="com-header-logo"
				style="width:100%;color:#FFFFFF;text-align:center;font-size:24px;">金穗采购</a>
			<div class="clear"></div>
		</div> -->
		<div id="toast" style="display: none;">
		    <div class="weui_mask_transparent"></div>
		    <div class="weui_toast">
		        <i class="weui_icon_toast"></i>
		        <p id="weui_toast_content" class="weui_toast_content">222</p>
		    </div>
		</div>
		<div class="com-content-area" id="js-com-content-area">
			<!--content-->
			<div class="page-role good-page">

				<div class="page-title" style="margin:0px 5px 10px 5px;">
					<a class="return" href="" onclick="closeWin();">返 回</a>商品详情
				</div>
				<div class="pxui-area">
					
					<div class="touchslider">
						<div class="touchslider-viewport"
							style="height:280px;overflow:hidden">
							<div>
								<div class="touchslider-item">
									<a><span class="img320"><dfn></dfn>
									<img id="img" src="" /></span></a>
								</div>
							</div>
						</div>
						<!--div class="touchslider-navtag">
								<a class="touchslider-prev"></a>
								<span class="touchslider-nav-item touchslider-nav-item-current"></span>
								<span class="touchslider-nav-item "></span>
								<span class="touchslider-nav-item "></span>
								<span class="touchslider-nav-item "></span>
								<span class="touchslider-nav-item "></span>
								<span class="touchslider-nav-item "></span>
								<span class="touchslider-nav-item "></span>
								<a class="touchslider-next"></a>
						</div-->
					</div>
					<div class="pxui-list" data-model="radio">
						<h1 id="title"></h1>
						<ul class="goodinfo" id="js-goodinfo">
							<li><b name="detail_mao" id="detail_mao">价&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;格:</b>
							<div>
									<p>
										<strong class="pxui-color-red" id="price">￥0.00</strong> 
									</p>
								</div></li>
							<li><b name="detail_mao" id="detail_mao">运&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;费:</b>
							<div>
									<p>
										四川省内包邮，省外另加邮费12元
									</p>
								</div></li>	
							<!-- <li><b>运&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;费:</b>
								<div>
									<p>
										<span>免运费 </span>
									</p>
								</div></li> -->
							<!-- <li><b>服&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;务:</b>
								<div>
									<p>由四川航天金穗高技术有限公司负责发货，并提供售后服务。</p>
								</div></li> -->
							<li><b style="line-height:39px;">数&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;量:</b>
								<div>
									<p>
										<span class="pxui-select num"> <span>1</span> <i></i> <select id="sl">
												<option value="1">1</option>
												<option value="2">2</option>
												<option value="3">3</option>
												<option value="4">4</option>
												<option value="5">5</option>
												<option value="6">6</option>
												<option value="7">7</option>
												<option value="8">8</option>
												<option value="9">9</option>
												<option value="10">10</option>
										</select>
										</span> <span class="pxui-color-red">
										</span>
									</p>
								</div></li>
						</ul>
						<input type="button" class="pxui-light-button addtocart" style="width:47%;margin-right:10px;" id="xgButton"
							value="选    购" onclick="subtj()"/>
						<input type="button" class="pxui-light-button addtocart" style="width:47%;"
							value="查 看 购 物 筐" onclick="location.href='bill.html'"/>
						<h3 id="js-attrs-title">商品描述</h3>
						<!-- <div class="attrs" id="spms">

						</div> -->
						<ul class="attrs" id="spms">
							<!-- <li>产品标准号: Q/CJJ0001S</li>
							<li>配料表: 兔肉、植物油、食用盐、白砂</li>
							<li>储藏方法: 冷藏保存</li>
							<li>口味: 香辣 五香口味 麻辣味</li>
							<li>净含量: 200g</li>
							<li>包装方式: 散装</li>
							<li>特产品类: 自贡冷吃兔</li>
							<li>系列: 冷吃系列</li>
							<li id="spms"></li> -->
						</ul>
					</div>
				</div>
			</div>
				</div>
				
				<!-- 加载动画 -->
	<div id="loadingToast" style="display:none;">
			<div class="weui-mask_transparent"></div>
			<div class="weui-toast">
				<i class="weui-loading weui-icon_toast"></i>
				<p class="weui-toast__content">数据加载中...</p>
			</div>
		</div>
		
<!-- <div class="com-footer-area" id="js-com-footer-area">
	<div class="com-footer-nav">
		<a href="main.html">首 页</a>
		<a href="history.html">历史订单</a>
		<a href="bill.html">购物筐</a>
	</div>
	<div class="com-footer">
		 © 2012-2018 四川航天金穗高技术有限公司 <br /> All Rights Reserved
		联系电话：028-66778822
	</div>
</div>
		</div> -->
	<div class="weui-tabbar">
			<div class="com-footer-area footer" id="js-com-footer" style="width:100%;">
				<img src="../../image/db.png" style="width:100%;"/>
			</div>
		</div>
  </body>
</html>
